package com.aponisipsis.gl3d.importer.json;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.aponisipsis.gl3d.geometry.Face;
import com.aponisipsis.gl3d.geometry.Mesh2D;
import com.aponisipsis.gl3d.geometry.UVMap;
import com.aponisipsis.gl3d.geometry.Vertex;

public class JSONMeshData {
	public String name;
	public 	float[] location;
	public float[][] vertices;
	public int[][] faces;
	public float[][][] uv;
	public String textureId;
	public int layer;
	
	public Mesh2D toMesh(){
		Vertex[] vtx = new Vertex[this.vertices.length];
		Face[] faces = new Face[this.faces.length];

		for(int c=0;c<this.vertices.length;c++){
			vtx[c] = new Vertex(this.vertices[c]);
		}
		
		for(int c=0;c<this.faces.length;c++){
			Vertex[] fvtx = new Vertex[this.faces[c].length];
			for(int v=0;v<this.faces[c].length;v++){
				fvtx[v]=vtx[this.faces[c][v]];
			}
			faces[c] = new Face(fvtx);
		}
		
		
		Mesh2D mesh = new Mesh2D(vtx,faces,this.uv);
		mesh.setName(name);
		mesh.setTextureId(this.textureId);
		mesh.setLayer(this.layer);
		//mesh.getTransform().translate(this.location[0],this.location[1],this.location[2]);
		return mesh;
	}
}
